//package com.tang.script.command;
//
//import com.tang.script.ScriptCommand;
//import com.tang.script.ScriptEngine;
//import com.tang.script.exceptions.ScriptException;
//import com.tang.script.extrator.ConstantsExtractor;
//import com.tang.script.extrator.FunctionsExtractor;
//import com.tang.script.extrator.VariablesExtractor;
//import com.tang.script.functions.FunctionsLinker;
//import com.tang.script.variable.Constant;
//import com.tang.script.variable.Variable;
//import com.tang.script.variable.VariableValueGetter;
//import com.tang.script.variable.VariablesContainer;
//import groovy.lang.Binding;
//import groovy.lang.GroovyShell;
//import groovy.lang.Script;
//import lombok.Getter;
//import lombok.Setter;
//
//import java.util.*;
//
//@Getter
//@Setter
//public abstract class AbstractScriptCommandBak<T> implements ScriptCommand<T> {
//    protected ScriptEngine scriptEngine;
//    protected String scriptText;
//    protected String resolvedScriptText;
//    protected Map<String, Variable> variables = new HashMap<>();
//    protected Map<String, Constant> constants = new HashMap<>();
//    protected List<String> functions = new LinkedList<>();
//
//    protected Binding binding;
//    VariableValueGetter variableValueGetter = new VariableValueGetter();
//    VariablesContainer variablesContainer;
//    ThreadLocal<GroovyShell> groovyShellThreadLocal = new ThreadLocal<>();
//    GroovyShell staticGroovyShellThreadLocal = new GroovyShell();
//
//    public AbstractScriptCommandBak(String scriptText, VariablesContainer variablesContainer) {
//        this.scriptText = scriptText;
//        this.variablesContainer = variablesContainer;
//    }
//
//    @Override
//    public T execute() {
//        initCommand();
//
//        ConstantsExtractor constantsExtractor = ConstantsExtractor.get();
//        constantsExtractor.extracte(this);
//
//        VariablesExtractor variablesExtractor = VariablesExtractor.get();
//        variablesExtractor.extracte(this);
//
//        FunctionsExtractor functionsExtractor = FunctionsExtractor.get();
//        functionsExtractor.extracte(this);
//
//        FunctionsLinker functionsLinker = FunctionsLinker.get();
//        functionsLinker.linkFunctions(this);
//
//        defineVariables();
//
//        return doExecute();
//    }
//
//    protected void defineVariables() {
//        for (Constant constant : constants.values()) {
//            getGroovyShell().setVariable(constant.getConstName(), variableValueGetter.getVariable(constant, variablesContainer));
//        }
//
//        for (Variable variable : variables.values()) {
//            getGroovyShell().setVariable(variable.getVarName(), variableValueGetter.getVariable(variable, variablesContainer));
//        }
//    }
//
//    protected void initCommand() {
//        scriptText = scriptText.replaceAll(" ", "");
//        setResolvedScriptText(getScriptText());
////        binding = new Binding();
////        groovyShell = new GroovyShell(binding);
//    }
//
//    protected T doExecute() {
//        GroovyShell groovyShell = getGroovyShell();
//        Script script = groovyShell.parse(this.resolvedScriptText);
//        Object result = getGroovyShell().evaluate(this.resolvedScriptText);
//        return toResult(result);
//    }
//
//    public T toResult(Object result) {
//        if (getResultClass().isAssignableFrom(result.getClass())) {
//            return (T) result;
//        }
//        throw new ScriptException("输出类型无法强制转换, 从" + result.getClass() + "到" + getResultClass());
//    }
//
//    public abstract Class getResultClass();
//
//    public GroovyShell getGroovyShell() {
//        if (true) {
//            return staticGroovyShellThreadLocal;
//        }
//        GroovyShell groovyShell = groovyShellThreadLocal.get();
//        if (Objects.isNull(groovyShell)) {
//            System.out.println(Thread.currentThread().getName());
//            groovyShellThreadLocal.set(groovyShell = new GroovyShell());
//        }
//        return groovyShell;
//    }
//}
